import { PipeTransform, Pipe } from '@angular/core';

/**
 * 过滤器
 * @param  {any} inputKey key
 * @param  {string} dicName 字典名称
 * @return {string}
 *
 *  数据结构：
 *  sample = {
     "key1" : 'value1',
     "key2" : 'value2',
     "key3" : 'value3',
 }
 *
 *  Usage:
 *   inputKey | xbTranslate:'dicName'
 * Example:
 *   {{ sample.key1 | xbTranslate:'sample' }}
 *   formats to: value1
 */
@Pipe({ name: 'pipelineFilter' })
export class PipelineFilter implements PipeTransform {

  demo = {
    name: 'name'
  };

  shopProjectSaleStatus = {
    '0': '出售中',
    '1': '已售罄',
    '2': '仓库中',
  };

  shopProjectOnlineStatus = {
    '0': '下架',
    '1': '上架',
  };

  shopProjectOnlineStatusTrans = {
    '0': '上架',
    '1': '下架',
  };

  withdrawStatus = {
    '0': '待审核',
    '1': '待打款',
    '2': '已打款',
    '3': '驳回',
  };

  withdrawType = {
    '0': '支付宝',
    '1': '微信',
  };

  transform(inputKey: any, dicName: string): string {
    // 返回本地数据的key对应的value
    if (inputKey !== null && dicName !== null && dicName.length > 0) {
      // return eval('this.' + dicName + '[\'' + inputKey + '\']');
      return this[dicName][inputKey];
    } else {
      return null;
    }
  }
}
